package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/28.
 */
@HttpInlet(Conn.GOODS_GOODS_CON)
public class GoodsDetailGet extends BaseAsyGet<GoodsDetailGet.GoodsDetailEntity> {

    public String gid;

    public GoodsDetailGet(AsyCallBack<GoodsDetailEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected GoodsDetailEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            GoodsDetailEntity goodsDetailEntity = new GoodsDetailEntity();

            JSONObject detialObject = object.optJSONObject("data");

            goodsDetailEntity.deprice = detialObject.optString("deprice");
            goodsDetailEntity.id = detialObject.optString("id");
            goodsDetailEntity.title = detialObject.optString("title");
            goodsDetailEntity.thumb = detialObject.optString("thumb");
            goodsDetailEntity.letter = detialObject.optString("letter");

            JSONArray array = detialObject.optJSONArray("picarr");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    goodsDetailEntity.picArr.add(Conn.IMAGE_URL + array.optString(i));

                }
            }

           return goodsDetailEntity;

        }

        return null;
    }

    public static class GoodsDetailEntity {

        public String id, title, deprice, thumb, letter;

        public List<String> picArr = new ArrayList<>();

    }

}
